package com.gpscookie.redpanic;

public class LinearRedDot extends RedDot {
	protected float bx;
	protected float by;
	protected float ex;
	protected float ey;
	protected float k;	
	protected float k2;

	public LinearRedDot(float beginx, float beginy, float endx, float endy, float sp) {
		super(beginx, beginy);
		bx = beginx;
		by = beginy;
		ex = endx;
		ey = endy;
		k = (ey-by)/(ex-bx);
		k2 = (ex-bx)/(ey-by);
		speed = sp;
	}
	
	@Override
	public void step() {
		if (bx==0) {
			x = x+speed;
			y = (x-bx)*k + by;
		} else {
			y = y+speed;
			x = (y-by)*k2 + bx;
		}
		// reset if go out
		if (x>=World.INSTANCE.width) {
			x = bx;
		}
		if (y>=World.INSTANCE.height) {
			y = by;
		}		
	}
}
